/**
 * @filename: mruse.js
 * @function: Common Script
 * @copyleft: CopyLeft
 * @author: MrUse
 * @email: 616574130@qq.com
 * @update: 2012.10
 */
var mruse = {
	ltrim : function (str) {
		var regExp = /^\s+/g;
		return str.replace(regExp, '');
	},
	rtrim : function (str) {
		var regExp = /\s+$/g;
		return str.replace(regExp, '');
	},
	trim : function (str) {
		return this.ltrim(this.rtrim(str));
	},
	isEmpty : function (str) {
		var regExp = /^\s+$/;
		return regExp.test(this.trim(str)) || str == '';
	},
	isInt : function (str) {
		var regExp = /^\d+$/;
		return regExp.test(this.trim(str));
	},
	isMobile : function (str) {
		var regExp = /^\+{0,1}(86){0,1}-{0,1}\d{11}$/;
		return regExp.test(this.trim(str));
	},
	isEmail : function (str) {
		var regExp = /^[a-z0-9_\-]+(\.[_a-z0-9\-]+)*@([_a-z0-9\-]+\.)+([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel)$/;
		return regExp.test(this.trim(str));
	},
	isIPv4 : function (str) {
		var regExp = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/;
		return regExp.test(this.trim(str));
	},
	isLink : function (str) {
		var regExp = /<a[^>]*href=\"[^\s\"]+\"[^>]*>[^<]*<\/a>/;
		return regExp.test(this.trim(str));
	},
	isURL : function (str) {
		var regExp = /^([a-z]+:\/\/)?([a-z]([a-z0-9\-]*\.)+([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel)|(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(:[0-9]{1,5})?(\/[a-z0-9_\-\.~]+)*(\/([a-z0-9_\-\.]*)(\?[a-z0-9+_\-\.%=&amp;]*)?)?(#[a-z][a-z0-9_]*)?$/;
		return regExp.test(this.trim(str));
	},
	isChinese : function (str) {
		var regExp = /[\u4e00-\u9fa5]{1,}/g;
		return regExp.test(this.trim(str));
	},
	isEnglish : function () {
		var regExp = /^\w+$/;
		return regExp.test(this.trim(str));
	},
	show : function () {
		var txt = '';
		for (k in this) {
			txt += 'mruse.' + k + '(str) or str.mruse("' + k + '")' + "\n";
		}
		txt += '\u611F\u8C22\u4F7F\u7528 mruse.js, \u6709\u95EE\u9898\u8BF7\u8054\u7CFB teachmyself@163.com \u6C9F\u901A\u4EA4\u6D41!';
		return txt;
	},
};
console.log(mruse.show());
String.prototype.mruse = function (fn) {
	var v = this.valueOf(),
		f = fn.toString();
	return mruse[f](v);
};
Array.prototype.unique = function () {
	var newArray = [],
		temp = {};
	for (var i = 0, item; (item = this[i]) != null; i++) {
		if (!temp[item]) {
			newArray.push(item);
			temp[item] = true;
		};
	};
	return newArray;
};
Array.prototype.indexOf || (Array.prototype.indexOf = function (i, k) {
	k || (k = 0);
	var t = this.length;
	if (k < 0)
		k = t + k;
	for (; k < t; k++)
		if (this[k] === i)
			return k;
	return -1
});
Array.prototype.shuffle || (Array.prototype.shuffle = function(){
	return this.sort(function(){
		return Math.round(Math.random());
	});
});
function bind(obj, eve, fun){
	if (obj.attachEvent) {
		obj.attachEvent(obj, click, fun);
	} else {
		obj.addEventListener(obj, eve, fun);
	};
};
function AddFavorite(sURL, sTitle) {
	try {
		window.external.addFavorite(sURL, sTitle);
	} catch (e) {
		try {
			window.sidebar.addPanel(sTitle, sURL, "");
		} catch (e) {
			alert("加入收藏失败，请使用Ctrl+D进行添加");
		};
	};
};
function SetHome(obj, vrl) {
	try {
		obj.style.behavior = 'url(#default#homepage)';
		obj.setHomePage(vrl);
	} catch (e) {
		if (window.netscape) {
			try {
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			} catch (e) {
				alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
			};
			var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage', vrl);
		};
	};
};
function noCopy(){
	document.oncontextmenu = new Function('event.returnValue=false');
	document.onselectstart = new Function('event.returnValue=false');
}
/*
无真(82502071)  9:47:13
谁有操作cookie的实例吗
[南宁]孟回头(279020623)  9:49:16
		setCookie : function(name, value, expire) {
			var date = new Date();
			expire = new Date(date.getTime() + expire * 60000);
			document.cookie = name + '=' + escape(value) + ';path=/;expires=' + expire.toGMTString() + ';';
		},
		getCookie : function(name) {
			var value = '',
				part,
			    pairs = document.cookie.split('; '),
				i = 0,
				len = pairs.length;
			for(; i < len; i++) {
				part = pairs[i].split('=');
				if(part[0] == name){
				value = unescape(part[1]);
			    }
			}
			return value;
		}
无真(82502071)  9:50:13
网上找的代码都是这样的差不多 可搞不懂 晕
沪∑黑执事帷云(976500133)  9:57:00
求哥getbyclass正则版本
[南宁]孟回头(279020623)  10:11:41
        getByClass: function (className, context) {
            context = context || document;
            if (context.getElementsByClassName) {
                return context.getElementsByClassName(className);
            }
            var nodes = context.getElementsByTagName('*'),
                ret = [],
                i = 0,
                len = nodes.length;
            for (; i < len; i++) {
                if (dream.hasClass(nodes[i], className)) ret.push(nodes[i]);
            }
            return ret;
        }
 hasClass: function (node, className) {
            return node.className.match(new RegExp('(\\s|^)' + className + '(\\s|$)'));
        }
.(371151708)  10:13:04
\\s/dd
中国龙行天下(79275412)  10:13:41
byClass: function(oParent,sClass) {
		var aClass = [];
		var reClass = new RegExp("(^| )" + sClass + "( |$)");
		var aElem = this.byTagName("*", oParent);
		for (var i = 0; i < aElem.length; i++) reClass.test(aElem[i].className) && aClass.push(aElem[i]);
		return aClass
	}
byTagName: function(elem, obj) {
		return (obj || document).getElementsByTagName(elem)
	}

*/